package com.bingo.controller;

import com.bingo.common.R;
import com.bingo.entity.HisPool;
import com.bingo.entity.Medication;
import com.bingo.entity.WaterQuality;
import com.bingo.entity.dto.req.CheckUser;
import com.bingo.entity.dto.req.ReqMedicationReport;
import com.bingo.entity.dto.req.ReqForm;
import com.bingo.service.HisPoolService;
import com.bingo.service.MedicationService;
import com.bingo.until.IsToday;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Date;

@RestController
@RequestMapping("/medication")
public class MedicationController {
    private MedicationService medicationService;
    @Autowired
    public void setFeedLossService(MedicationService medicationService) {
        this.medicationService = medicationService;
    }

    private HisPoolService hisPoolService;
    @Autowired
    public void setHisPoolService(HisPoolService hisPoolService) {
        this.hisPoolService = hisPoolService;
    }

//    @PostMapping("/report")
//    public R Medication(@RequestBody ReqMedicationReport reqMedicationReport) {
//        if (!IsToday.isToday(reqMedicationReport.getDate())){
//            HisPool pool = hisPoolService.getPoolByNo(reqMedicationReport.getPoolNo());
//            if (pool == null || pool.getType() == 0){
//                return R.error("不存在该池塘或为空塘!");
//            }
//        }
//        return medicationService.add(reqMedicationReport.getPoolNo(), reqMedicationReport.getFeed(), reqMedicationReport.getLoss(), reqMedicationReport.getLossWeight(),reqMedicationReport.getDate(), reqMedicationReport.getUserId());
//    }
    @PostMapping("/record")
    public R medicationRecord(@RequestBody ReqForm reqForm) {
        return R.success(medicationService.selectMedicationRecord(reqForm.getPoolNos(), reqForm.getDate()[0], reqForm.getDate()[1],reqForm.getUserId()));
    }

    @PostMapping("/delete")
    public R deleteMedicationRecord(@RequestBody Medication medication){
        boolean delete = medicationService.deleteMedicationRecord(medication);
        if (!delete){
            return R.error("删除失败！");
        }
        return R.success("删除成功！");
    }

    @PostMapping("/add")
    public R addMedicationRecord(@RequestBody Medication medication){
        return medicationService.add(medication);
    }
    @PostMapping("/update")
    public R updateMedicationRecord(@RequestBody Medication medication) {
        return R.success(medicationService.update(medication));
    }


}
